package ca.uvic.cs.cogz.mapping.ui;

import javax.swing.tree.TreePath;

import ca.uvic.cs.cogz.mapping.ui.tree.FilteredParentChildNode;
import ca.uvic.cs.cogz.mapping.ui.tree.MappingJTree;

public class NotificationManager {
	private static NotificationManager notificationManager;
	
	private FilteredParentChildNode currentlySelected;
	
	private NotificationManager() {}
	
	public static NotificationManager getInstance() {
		if(notificationManager == null) {
			notificationManager = new NotificationManager();
		}
		
		return notificationManager;
	}
	
	public void createNotification(MappingJTree tree, boolean mappingExists) {
		if(currentlySelected != null) {
			currentlySelected.setMappingFiltered(false);
		}
		
		TreePath path = tree.getSelectionPath();
		if(path != null && path.getLastPathComponent() instanceof FilteredParentChildNode) {
			FilteredParentChildNode treeNode = (FilteredParentChildNode)path.getLastPathComponent();
			treeNode.setMappingFiltered(!mappingExists);
			
			currentlySelected = treeNode;
			
			tree.refreshTree();
		}
	}
}
